import lombok.extern.log4j.Log4j;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.InputStream;
import java.util.Map;
@Log4j
public class ConfigLoader {
    private Map<String, Object> config;

    public ConfigLoader(String fileName) {
        Yaml yaml = new Yaml(new Constructor(Map.class));
        try (InputStream in = ConfigLoader.class
                .getClassLoader()
                .getResourceAsStream(fileName)) {
            config = yaml.load(in);
            config = (Map<String, Object>) config.get("app");
        } catch (Exception e) {
            log.error("加载配置文件出错", e);
        }
    }

    public String getRegistryHost() {
        Map<String, Object> registry = (Map<String, Object>) config.get("registry");
        return (String) registry.get("host");
    }

    public int getRegistryPort() {
        Map<String, Object> registry = (Map<String, Object>) config.get("registry");
        return (Integer) registry.get("port");
    }
}

